﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using Microsoft.VisualBasic.FileIO;

namespace Domain {
  public class CSVFileChecker {

    private static CSVFileChecker checker;
    private String path;
    private TextFieldParser parser;

    private CSVFileChecker(String path) {
      this.path = path;
    }

    public Boolean CheckFileHeading() {
      parser = new TextFieldParser(path);
      parser.TextFieldType = FieldType.Delimited;
      parser.SetDelimiters(";");
      while (!parser.EndOfData) 
      {
          //Processing row
          string[] fields = parser.ReadFields();
          if (fields.Length == 2) {
            if (fields[0].ToLower().Equals("nr") &&
                fields[1].ToLower().Equals("name")) {
                  //FinishParsing();
                return true;
            }
          }

      }
      FinishParsing();
      return false;
    }

    public void FinishParsing() {
      parser.Close();
      System.IO.File.Delete(path);
    }

    public static CSVFileChecker GetInstance(string path) {
      if (checker == null) {
        checker = new CSVFileChecker(path);
      }
      return checker;
    }
  }
}
